# 一键部署LNMP环境
# ################
# nginx-1.11.5
# php-7.0.8
# mysql-5.7.13
# redis-3.2.1
# ################

FROM centos:7
MAINTAINER oldzhuang <zql_0539@163.com>

# yum update
RUN yum -y install epel-release && yum -y update
# install package
RUN yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-turbo-devel libjpeg-devel libpng libpng-devel gd-devel freetype freetype-devel libmcrypt-devel libmcrypt libcurl-devel libxslt-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers vim wget openssh-server openssh-clients libiconv-devel autoconf psmisc libuuid-devel unzip

RUN mkdir -p /application/{nginx,php,mysql,redis,phpredis,phpyaf,phpuuid}
WORKDIR /application/nginx
RUN wget http://nginx.org/download/nginx-1.11.5.tar.gz
WORKDIR /application/php
RUN wget http://mirrors.sohu.com/php/php-7.0.8.tar.gz
WORKDIR /application/phpredis
RUN wget https://github.com/phpredis/phpredis/archive/php7.zip
WORKDIR /application/phpyaf
RUN wget http://pecl.php.net/get/yaf-3.0.3.tgz
WORKDIR /application/phpuuid
RUN wget http://pecl.php.net/get/uuid-1.0.4.tgz
WORKDIR /application/redis
RUN wget http://download.redis.io/releases/redis-3.2.1.tar.gz
#WORKDIR /application/mysql
#RUN wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz

# install nginx
RUN useradd nginx -s /sbin/nologin -M
WORKDIR /application/nginx
RUN tar xf nginx-1.11.5.tar.gz
WORKDIR nginx-1.11.5
RUN ./configure --prefix=/application/nginx/nginx-1.11.5 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --conf-path=/application/nginx/nginx-1.11.5/nginx.conf && make && make install

# config nginx
RUN ln -s /application/nginx/nginx-1.11.5 /application/nginx/nginx
RUN echo '/application/nginx/nginx/sbin/nginx' >> /etc/rc.local

# install php
WORKDIR /application/php
RUN tar xf php-7.0.8.tar.gz
WORKDIR php-7.0.8
RUN ./configure \
	--prefix=/application/php/php-7.0.8 \
	--with-mysql=mysqlnd \
	--with-pdo-mysql=mysqlnd \
	--with-mysqli=mysqlnd \
	--with-iconv-dir=/usr/local/libiconv \
	--with-freetype-dir \
	--with-jpeg-dir \
	--with-png-dir \
	--with-zlib \
	--with-libxml-dir \
	--enable-xml \
	--disable-rpath \
	--enable-bcmath \
	--enable-shmop \
	--enable-sysvsem \
	--enable-inline-optimization \
	--with-curl \
	--enable-mbregex \
	--enable-fpm \
	--enable-mbstring \
	--with-mcrypt \
	--with-gd \
	--enable-gd-native-ttf \
	--with-openssl \
	--with-mhash \
	--enable-pcntl \
	--enable-sockets \
	--with-xmlrpc \
	--enable-zip \
	--enable-soap \
	--enable-short-tags \
	--enable-static \
	--with-xsl \
	--with-fpm-user=nginx \
	--with-fpm-group=nginx \
	--enable-opcache=no  \
	--enable-ftp
RUN make && make install

# config php
RUN ln -s /application/php/php-7.0.8 /application/php/php
RUN echo '/application/php/php/sbin/php-fpm' >> /etc/rc.local
RUN cp /application/php/php-7.0.8/php.ini-production /application/php/php/lib/php.ini
RUN cp /application/php/php/etc/php-fpm.conf.default /application/php/php/etc/php-fpm.conf
RUN cp /application/php/php/etc/php-fpm.d/www.conf.default /application/php/php/etc/php-fpm.d/www.conf

# install redis
WORKDIR /application/redis
RUN tar xf redis-3.2.1.tar.gz
WORKDIR redis-3.2.1
RUN make

# config redis
RUN ln -s /application/redis/redis-3.2.1 /application/redis/redis
RUN sed -i 's/daemonize\ yes/daemonize\ no/' /application/redis/redis/redis.conf

# install phpredis
WORKDIR /application/phpredis
RUN unzip php7.zip
WORKDIR phpredis-php7
RUN /application/php/php/bin/phpize
RUN ./configure --with-php-config=/application/php/php/bin/php-config 
RUN make && make install

# install phpyaf
WORKDIR /application/phpyaf
RUN tar xf yaf-3.0.3.tgz
WORKDIR yaf-3.0.3
RUN /application/php/php/bin/phpize
RUN ./configure --with-php-config=/application/php/php/bin/php-config
RUN make && make install

# install phpuuid
WORKDIR /application/phpuuid
RUN tar xf uuid-1.0.4.tgz
WORKDIR uuid-1.0.4
RUN /application/php/php/bin/phpize
RUN ./configure  --with-php-config=/application/php/php/bin/php-config
RUN make && make install

# install mysql
#WORKDIR /application/mysql
#RUN tar xf mysql-5.7.13.tar.gz
#WORKDIR /application/mysql/mysql-5.7.13
#RUN cmake -DCMAKE_INSTALL_PREFIX=/application/mysql/mysql \
#          -DMYSQL_DATADIR=/application/mysql/mysql/data \
#          -DSYSCONFDIR=/etc \
#          -DWITH_MYISAM_STORAGE_ENGINE=1 \
#          -DWITH_INNOBASE_STORAGE_ENGINE=1 \
#          -DWITH_MEMORY_STORAGE_ENGINE=1 \
#          -DWITH_READLINE=1 \
#          -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
#          -DMYSQL_TCP_PORT=3306 \
#          -DENABLED_LOCAL_INFILE=1 \
#          -DWITH_PARTITION_STORAGE_ENGINE=1 \
#          -DEXTRA_CHARSETS=all \
#          -DDEFAULT_CHARSET=utf8 \
#          -DDEFAULT_COLLATION=utf8_general_ci
#RUN make
#RUN make install
#RUN mkdir -p /application/mysql/mysql/data
#RUN useradd mysql
#RUN chown -R mysql /application/mysql/mysql/data
#RUN /application/mysql/mysql/bin/mysqld --initialize --initialize-insecure --basedir=/application/mysql/mysql --datadir=/application/mysql/mysql/data --user=mysql

#config mysql
#RUN cp /application/mysql/mysql/support-files/mysql.server /etc/init.d/mysqld && chmod +x /etc/init.d/mysqld

## allow ports 
EXPOSE 80
EXPOSE 443
EXPOSE 6379
#EXPOSE 3306

ADD ./start.sh /start.sh
RUN chmod +x /start.sh
CMD ["/start.sh"]
